<?php defined("MAIN_DIR") or die("No direct access");

$bank_id = UV::readInt($route->getPath(3));

$bank_res = mysql_query("select `bank_id`,`name` from `bank` where `bank_id` = '$bank_id' limit 1");
if (mysql_num_rows($bank_res) == 0) {
	to("/admin/atms/");
}

$bank_row = mysql_fetch_array($bank_res);

require_once ADMIN.HEADFILE;
?>
<div align="left">
<h1>Список банкоматов - <?php echo $bank_row['name']; ?></h1><?php
$atms_query = "select `atm_id`,`address` from `atm` where `bank_id` = '$bank_row[bank_id]'";

$limit = 10;
$atms_res = mysql_query($atms_query);
$count = mysql_num_rows($atms_res);
$page = 1;
if (isset($_GET['page']))
	$page = $_GET['page'];
$max_page = ceil($count/$limit);
if ($max_page == 0)
	$max_page++;
if ($page > $max_page)
	$page = $max_page;
elseif ($page < 1)
	$page = 1;
$start_list = (ceil($page)-1)*$limit;
$atms_query .= " limit $start_list,$limit";
$atms_res = mysql_query($atms_query);
$atms_count = mysql_num_rows($atms_res);
?>
<table cellpadding="5" cellspacing="0" class='light'>
	<tr id='header'>
		<td width="30px" style="border-bottom:1px gray solid">ID</td>
		<td width="300px" style="border-bottom:1px gray solid">Адрес</td>
		<td width="200px" style="border-bottom:1px gray solid">Действия</td>
	</tr><?php
	while ($atms_row = mysql_fetch_array($atms_res))
	{
		?><tr>
			<td><?php echo $atms_row['atm_id']?></td>
			<td><?php echo $atms_row['address']?></td>
			<td>
				<a href='/admin/atms/edit/<?php echo $atms_row['atm_id']?>'>Редактировать</a> |
				<a onclick='return confirm_del()' href='/admin/atms/delete/<?php echo $atms_row['atm_id']?>?bank_id=<?php echo $bank_id; ?>'>Удалить</a>
			</td>
		</tr><?php
	}
?></table>
<br /><a href='/admin/atms/add/?bank_id=<?php echo $bank_row['bank_id'];?>'>Добавить банкомат</a><br />
<br /><a href='/admin/atms/'>Назад</a>
<br /><?php require_once APP."pageskin.php"; ?>
</div>

<?php require_once ADMIN.FOOTERFILE; ?>